/*
 * AbstractThread.h
 *
 *  Created on: 2022年9月15日
 *      Author: wocao
 */

#include <pthread.h>
#ifndef THREAD_ABSTRACTTHREAD_H_
#define THREAD_ABSTRACTTHREAD_H_
class Threadpool;
class AbstractThread {
public:
	AbstractThread();
	virtual ~AbstractThread();
	virtual void start();//線程開始執行
	static void* cutplane(void *vo);//用此方法創建線程（切面方法）
	pthread_t getPthread_id() {
		return this->tid;
	}
	void setArg(void *arg) {
		this->arg = arg;
	}
	void* getArg() {
		return (void*) arg;
	}

	void*(* getRun(void))(void*) {
		return run;
	}

	void setRun(void* (*run)(void*)){
		this->run = run;
	}

	pthread_mutex_t* getMutex(){
		return this->mutex;
	}
	pthread_cond_t* getPcond(){
		return this->pcond;
	}
	Threadpool* getPool(){
		return this->pool;
	}
	bool getFlag(){
		return this->flag;
	}
	void setFlag(bool flag){
		this->flag = flag;
	}
protected:
	void* (*run)(void*) = NULL;//傳入的線程函數指針
	volatile void *arg = NULL;//傳入的線程函數的參數
	bool flag = true;
	pthread_t tid = 0;
	pthread_mutex_t *mutex = NULL;
	pthread_cond_t *pcond = NULL;
	Threadpool *pool = NULL;//線程池指針
};
#endif /* THREAD_ABSTRACTTHREAD_H_ */
